<h2>修改目录</h2>
<div id="manage-file-fold-modify"
     data-topple="hsForm"
     data-save-url="common/fold/update.act">
    <form action="" method="POST">
        <input type="hidden" name="path" data-fn/>
        <input type="hidden" name="type" value="dir"/>
        <div class="form-group row">
            <label class="col-xs-3 text-right form-label control-label form-control-static">目录名</label>
            <div class="col-xs-6">
                <input type="text" name="name" class="form-field form-control" required="required"/>
            </div>
        </div>
        <hr/>
        <div class="row">
            <div class="col-xs-6 col-xs-offset-3">
                <button type="submit" class="commit btn btn-primary">改名</button>
                <button type="button" class="cancel btn btn-link"   >取消</button>
            </div>
        </div>
        <br/>
    </form>
</div>
<script type="text/javascript">
    (function($) {
        var context = H$("#manage-file-fold-modify");
        var loadbox = context.closest(".loadbox");
        var loadpms = hsSerialArr(loadbox       );
        var path    = hsGetSeria (loadpms,"path");
        var name    = path.replace (/^.*\// , '');

        context.find("[name='path']").val( path );
        context.find("[name='name']").val( name );

        context.find("form").on("submit", function(evt) {
            var form = $(this);
            var inst = context.data( "HsForm" );
            var path = form.find("[name=path]").val();
            var name = form.find("[name=name]").val();
            var dist = path.replace(/\/[^\/]*$/, '' );
            var data = {
                dist : dist + "/" + name,
                path : path,
                type : "dir"
            };
            evt.stopPropagation();
            evt.preventDefault( );
            if (!inst.validate()) {
                return false;
            }
            jQuery.hsAjax({
                "url"       : form.attr("action"),
                "data"      : data,
                "type"      : "POST",
                "dataType"  : "json",
                "funcName"  : "save",
                "async"     : false,
                "cache"     : false,
                "global"    : false,
                "context"   : inst,
                "complete"  : inst.saveBack,
                "error"     : function() { return false; }
            });
            return false;
        });
    })(jQuery);
</script>
